[PHP] Read and write to a file while keeping lock
Posted
by Znarkus
on Stack Overflow
See other posts from Stack Overflow
or by Znarkus
Published on 2010-03-15T22:15:29Z
Indexed on
2010/03/15
22:19 UTC
Read the original article
Hit count: 251
Hi!
I am making a simple page load counter by storing the current count in a file. This is how I want to do this:
- Lock the file
- Read the current count
- Increment it
- Write new count
- Unlock file/close it
Can this be done?
As I understand it, the file can't be written to without losing the lock. The only way I have come up with to tackle this, is to write a character using "r+" mode, and then counting characters.
© Stack Overflow or respective owner